package com.discuz.post;

import java.util.List;

import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;

@SuppressWarnings("deprecation")
public class HttpUtils {

	private static DefaultHttpClient client; 
	
	
	public static DefaultHttpClient get(){
		
		if(client == null){
			 client = new DefaultHttpClient();
			 HttpClientParams.setCookiePolicy(client.getParams(),
						CookiePolicy.BROWSER_COMPATIBILITY);

		}
		
		return client;
	}
	
	public static  void destory(){
		client.getConnectionManager().shutdown();
	}
	
	public static String checkCookie() {

		List<Cookie> cookies = client.getCookieStore().getCookies();
		String tmpcookies = "";
		for (Cookie c : cookies) {
			tmpcookies += (c.getName() + "=" + c.getValue());
			tmpcookies += ";";
		}
		return tmpcookies;
	}
}
